<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>

<head>
	<script type="text/javascript">
		$.subscribe('afficherDetailSourceFactureLien', function(event,data) {
			
			var grid = event.originalEvent.grid;
			var ligneId = grid.jqGrid('getGridParam', 'selrow');
			var sourceFactureId = grid.jqGrid('getCell', ligneId, 'id');
			
			var form = document.getElementById('afficherDetailSourceFacture');
			
			if (form.idSourceFactureSelectionnee.value != sourceFactureId) {
				form.idSourceFactureSelectionnee.value = sourceFactureId;
				form.submit();
			}
			
		});
	</script>
</head>
<s:div id="tableauSourcesFacture">
	<s:url var="remplirListeSourceAction" action="remplirListeSourcesfacture" />
	<s:text name="facture.sourceFacture.titreTableau" var="titreTableau" />
	<sjg:grid gridModel="listeTableau" caption="%{titreTableau}" dataType="json"
			href="%{remplirListeSourceAction}" pager="true" pagerInput="false"
			rownumbers="true" rowList="10,20,30" viewrecords="true" autowidth="true"
			hidegrid="true" onSelectRowTopics="afficherDetailSourceFactureLien">
		<s:text name="id" var="titreId" />
		<sjg:gridColumn name="id" key="true" index="id" title="%{titreId}" hidden="true" />
		<s:text name="libelle" var="titreLibelle" />
		<sjg:gridColumn name="libelle" index="libelle" title="%{titreLibelle}" />
	</sjg:grid>
</s:div>
<s:div cssStyle="margin-top:20px;">
	<s:fielderror />
	<s:actionmessage />
	<s:actionerror />
	<s:text var="titreAjoutSource" name="facture.sourceFacture.ajouterSource.titrePanel" />
	<sj:accordion heightStyle="content" animate="true" collapsible="true" active="false">
		<sj:accordionItem title="%{titreAjoutSource}">
			<table>
				<tr>
					<td>
						<s:form id="formAjouterSource" action="ajouterSourceFacture" validate="true">
							<s:text var="libelleLibelle" name="libelle" />
							<s:textfield name="sourceFactureAjout.libelle" label="%{libelleLibelle}" />
						</s:form>
					</td>
					<td align="center" valign="middle" width="250px">
						<sj:a formIds="formAjouterSource" button="true" buttonIcon="ui-icon-plusthick">
							<s:text name="commun.bouton.ajouter.titre" />
						</sj:a>
					</td>
				</tr>
			</table>
		</sj:accordionItem>
	</sj:accordion>
</s:div>
<s:div cssStyle="margin-top:20px;">
	<s:form action="afficherDetailSourceFacture">
		<s:hidden name="idSourceFactureSelectionnee" />
	</s:form>
	<s:if test="idSourceFactureSelectionnee != null">
		<s:form id="supprimerSourceFacture" action="supprimerSourceFacture">
			<s:hidden name="idSourceFactureSelectionnee" />
		</s:form>
		<s:push value="sourceFactureModif">
			<s:text var="titreDetailSourceFacture" name="facture.sourceFacture.detailSourceFacture.titrePanel">
				<s:param><s:property value="libelle" /></s:param>
			</s:text>
		</s:push>
		<sj:accordion heightStyle="content" animate="true" collapsible="true">
			<sj:accordionItem title="%{titreDetailSourceFacture}">
				<table>
					<tr>
						<td>
							<s:form id="formModifierFacture" action="modifierSourceFacture" validate="true">
								<s:hidden name="idSourceFactureSelectionnee" />
								<s:textfield name="sourceFactureModif.libelle" label="%{libelleLibelle}"  />
							</s:form>
						</td>
						<td align="center" valign="middle" width="150px">
							<sj:a formIds="formModifierFacture" button="true" buttonIcon="ui-icon-pencil" cssStyle="width:94%;">
								<s:text name="commun.bouton.modifier.titre" />
							</sj:a>
							<sj:a formIds="supprimerSourceFacture" button="true" buttonIcon="ui-icon-closethick" cssStyle="margin-top:15px;width:94%;">
								<s:text name="commun.bouton.supprimer.titre" />
							</sj:a>
						</td>
					</tr>
				</table>
			</sj:accordionItem>
		</sj:accordion>
	</s:if>
</s:div>